#!/bin/bash

# 修改主机密码
function change_passwd() {
    echo "root:Huawei12#$" | chpasswd
}

# 生成 ssh key, 如果已经存在,则自动跳过 
function gen_sshkey() {
    cat /dev/zero | ssh-keygen -q -N ""; echo
}

# 设置 hostname
function set_hostname() {
    HOSTNAME=$1
    hostnamectl set-hostname $HOSTNAME
}

# 配置静态 ip
function set_ip() {
    IP=$1
    DEV=$2
    nmcli con add con-name ${DEV} type ethernet ifname ${DEV} ipv4.method manual autoconnect yes ipv4.addresses ${IP}/24 ipv4.gateway 192.168.122.1 ipv4.dns 192.168.122.1
    nmcli con up ${DEV}
}


function main() {
    change_passwd
    gen_sshkey
    set_hostname $1
    set_ip $2 $3
}

# 使用: main hostname1 192.168.122.101 eth0
main $@
